package com.enzoism.springboot.dive.controller;

import com.enzoism.springboot.dive.model.SportModel;
import com.enzoism.springboot.dive.result.RequestResult;
import com.enzoism.springboot.dive.service.SportESService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/es")
public class ESController {

    @Autowired
    private SportESService sportEsService;

    /**
     * 创建索引
     */
    @PostMapping("/createIndex")
    public RequestResult createIndex() {
        sportEsService.createIndex();
        return RequestResult.success("创建索引[数据库]成功");
    }

    /**
     * 索引中添加文档
     */
    @PostMapping("/saveDocument")
    public RequestResult saveDocument(@RequestBody SportModel sportModel) {
        sportEsService.saveDocument(sportModel);
        return RequestResult.success("保存文档[表]成功");
    }

    /**
     * 索引中查询文档
     */
    @PostMapping("/getDocument")
    public RequestResult getDocument(@RequestBody SportModel sportModel) {
        return RequestResult.success(sportEsService.getDocument(sportModel));
    }
}